package com.wwj.my_ummary.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wwj.my_ummary.config.cache.annotation.AddCacheAnnotation;
import com.wwj.my_ummary.config.cache.annotation.DeleteCacheAnnotation;
import com.wwj.my_ummary.user.entity.User;
import com.wwj.my_ummary.user.mapper.UserMapper;
import com.wwj.my_ummary.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wwj
 * @since 2020-12-25
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @AddCacheAnnotation(redisKey = "selectList")
    @Override
    public List<User> selectList() {
        QueryWrapper<User> wrapper = new QueryWrapper<>();

        return userMapper.selectList(wrapper);
    }

    @DeleteCacheAnnotation()
    @Override
    public int insert(User user) {

        int insert = userMapper.insert(user);
        return insert;
    }

    @Override
    public User findByUsername(String username) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq(User.USER,username);
        return  userMapper.selectOne(wrapper);
    }

    @Override
    public Set<String> findPermissions(String username) {
        Set<String> permissions = new HashSet<>();
        permissions.add("sys:user:view");
        permissions.add("sys:user:add");
        permissions.add("sys:user:edit");
        permissions.add("sys:user:delete");
        return permissions;
    }
}
